package fr.mairie.parc.page.admin;

import org.apache.click.ActionListener;
import org.apache.click.Control;
import org.apache.click.control.FileField;
import org.apache.click.control.Form;
import org.apache.click.control.Submit;
import org.apache.click.util.ClickUtils;

import fr.mairie.parc.page.BorderPage;

public class SaisirListeDesPcPage extends BorderPage {

	private static final long serialVersionUID = 1L;

	private Form form = new Form("form");
	private Submit submit = new Submit("ok");

	// Event Handlers ---------------------------------------------------------

	@Override
	public void onInit() {
		super.onInit();

		form.setJavaScriptValidation(true);

		// NB: when using form.submit() the submit button cannot be
		// called 'submit'. If it is, the browser is likely to throw a JS
		// exception.

		form.add(new FileField("Plan de remplacement"));

		form.add(submit);
		addControl(form);

		// NB: Bind the submit button. If it wasn't clicked it means the Form
		// was submitted
		// using JavaScript and we don't want to validate yet
		ClickUtils.bind(submit);

		// If submit was not clicked, don't validate
		if (form.isFormSubmission() && !submit.isClicked()) {
			form.setValidate(false);
			addModel("msg", "Validation is bypassed");
		}

		submit.setActionListener(new ActionListener() {
			private static final long serialVersionUID = 1L;

			public boolean onAction(Control source) {
				if (form.isValid()) {
					addModel("msg", "Le formulaire est valide");
				}
				return true;
			}
		});
	}

}
